package edu.ycxy.poetry.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ycxy.poetry.entity.ChengYu;
import edu.ycxy.poetry.vo.AddIdiomVo;
import edu.ycxy.poetry.vo.UpdateIdiomVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/8
 * @Description
 */
@Repository
public interface ChengYuMapper extends BaseMapper<ChengYu> {

    //查询所有的成语内容
    @Select("select * from vab_chengyu")
    List<ChengYu> selectListToIdiom();

    //根据成语名查询成语的详细信息
    @Select("select * from vab_chengyu where title=#{title}")
    ChengYu selectIdiomByTitle(String idiomName);

    //新增成语
    @Insert("insert into vab_chengyu(title,pinyin,txt,chuchu,liju,type) values (#{title},#{pinyin},#{txt},#{chuchu},#{liju},#{type})")
    Integer addIdiom(AddIdiomVo addIdiomVo);

    // 模糊查询
    @Select("select * from vab_chengyu where title like CONCAT('%',#{title},'%')")
    List<ChengYu> findListByFuzzy(String title);

    @Delete("delete from vab_chengyu where id=#{id}")
    Integer deleteIdiom(Integer id);

    @Select("select * from vab_chengyu where id=#{id}")
    ChengYu findOneById(Integer id);

    @Update("update vab_chengyu set title=#{title},pinyin=#{pinyin},txt=#{txt},chuchu=#{chuchu},liju=#{liju},type=#{type} where id=#{id}")
    Integer updateIdiom(UpdateIdiomVo updateIdiomVo);
}
